package com.jjb.saas.demo.infrastructure.queryservice.impl;

import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.demo.infrastructure.converter.RoleConvertor;
import com.jjb.saas.demo.infrastructure.persistence.domainobject.RoleDO;
import com.jjb.saas.demo.infrastructure.persistence.repository.RoleRepository;
import com.jjb.saas.demo.infrastructure.queryservice.RoleQueryService;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.system.client.role.request.RolePageQry;
import com.jjb.saas.system.client.role.response.RoleCO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author tzh * @date 2022年07月08日 18:46
 */
@Service
@AllArgsConstructor
public class RoleQueryServiceImpl implements RoleQueryService {
    private final RoleRepository roleRepository;
    private final RoleConvertor roleConvertor;



    @Override
    public PageResponse<RoleCO> listPage(RolePageQry qry) {
        IPage<RoleDO> page = roleRepository.rolePage(PageHelper.queryToPage(qry), qry);
        return PageHelper.pageToResponse(page,roleConvertor.convertDOSToCOS(page.getRecords()));

    }

    @Override
    public RoleDO getById(Long id) {
        return roleRepository.getById(id);
    }


    @Override
    public Boolean hasUsed(Long id) {
        return false;
    }

}
